home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / gemfsc20 / gemfsc20.lzh / GNUGEM27 / COMMON.C < prev    next >
C/C++ Source or Header  |  1993-03-24  |  4KB  |  162 lines

  1. /*
  2.  * Common part of gemlib bindings
  3.  *
  4.  *    ++jrb    bammi@cadence.com
  5.  *    modified: mj -- ntomczak@vm.ucs.ualberta.ca
  6.  */
  7. #define __IN_COMMON_C
  8. #include "common.h"
  9.  
  10. /* vdi binding arrays (extern everywhere else) */
  11. unsigned short    _contrl[CNTRLMAX];
  12. short        _intin[INTINMAX];
  13. short        _intout[INTOUTMAX];
  14. short        _ptsin[2 * PTSINMAX];    /* upto PTSINMAX vertices are allowed
  15.                        - currently 1024 */
  16. short        _ptsout[2 * PTSOUTMAX]; /* likewise */
  17.  
  18. /*
  19.  * aes binding arrays  - we need only global, other overlapped with
  20.  * arrays for vdi - see common.h
  21.  */
  22. unsigned short    _global[GLOBMAX];    /* this should be exact */
  23.  
  24. /* aes binding params */
  25. void    *_aesparams[6] =       { (void *)&_control[0],
  26.                      (void *)&_global[0],
  27.                  (void *)&_int_in[0],
  28.                  (void *)&_int_out[0],
  29.                  (void *)&_addrin[0],
  30.                  (void *)&_addrout[0] };
  31. /* why did atari do this when apid is avail on appl_init ?? */
  32. int gl_apid;            /* initialized in appl_init */
  33. int gl_ap_version;        /* initialized in appl_init */
  34.  
  35. /* vdi binding params */
  36. void    *_vdiparams[5] =       { (void *)&_contrl[0],
  37.                  (void *)&_intin[0],
  38.                  (void *)&_ptsin[0],
  39.                  (void *)&_intout[0],
  40.                  (void *)&_ptsout[0] };
  41. /*
  42.  * the common interface to aes
  43.  *    int __aes__(coded control);
  44.  *    unsigned long coded control;
  45.  * coded control: (1 byte for each element of control in the long)
  46.  *    DD CC BB AA
  47.  * DD : aes opcode
  48.  * CC : sizeof _int_in
  49.  * BB : sizeof _int_out
  50.  * AA : sizeof _addrin
  51.  *
  52.  * Note: sizeof _addrout is needed only for rsrc_gaddr and is special
  53.  *     cased below.
  54.  *
  55.  * output: the value (int)_intout[0]
  56.  */
  57.  
  58. #ifdef __OLD__
  59. int __aes__(unsigned long coded_control)
  60. {
  61.     register unsigned char    *p = (unsigned char *)&coded_control;
  62.     register unsigned short *q = &_control[0];
  63.  
  64.     /* decode control */
  65.     do
  66.     {
  67.     *q++ = (unsigned short)(*p++);
  68.     } while(q < &_control[4]);
  69.  
  70.     /* only rsrc_gaddr() needs this */
  71.     *q = (_control[0] == 112) ? 1 : 0;
  72.  
  73.     /* call aes */
  74.     __asm__ volatile
  75.     ("  movl    %0,    d1
  76.         movw    #0xc8, d0
  77.         trap    #2"
  78.      :                /* no outputs */
  79.      : "g"(&_aesparams[0])  /* inputs     */
  80.      : "d0", "d1", "d2", "a0", "a1", "a2"    /* clobbered regs */
  81.      );
  82.     return (int)_int_out[0];
  83. }
  84. #else
  85. /*
  86.  * new more efficient coding thanks to Thomas Koenig (UI0T@DKAUNI2.BITNET)
  87.  * "I made use here of the movep instruction for the 680xx, which transfers
  88.  * data from a data register to alternate bytes of memory. The odd
  89.  * address makes sure that these bytes are transferred to the lower half
  90.  * of the words."
  91.  */
  92. int __aes__(unsigned long coded_control)
  93. {
  94.  
  95.     /* call aes */
  96.     __asm__ volatile
  97.     ("  movel   %1,  d1
  98.         lea __contrl, a0    | arrays _contrl and _control overlap
  99.     moveq    #0,  d0
  100.     movepl    d0,  a0@(0) | clear high bytes of control array
  101.         movepl    d1,  a0@(1)
  102.         movl    %0,    d1
  103.         movw    #0xc8, d0    | note -- no movq here, it sign extends
  104.         trap    #2"
  105.      :                /* no outputs */
  106.      : "g"(&_aesparams[0]), "g"(coded_control)  /* inputs     */
  107.      : "d0", "d1", "d2", "a0", "a1", "a2"    /* clobbered regs */
  108.      );
  109.     return (int)_int_out[0];
  110. }
  111. #endif
  112.  
  113. /*
  114.  * the common interface to vdi
  115.  *    void __vdi__(coded contrl, handle);
  116.  *    unsigned long coded contrl;
  117.  *    int handle;
  118.  * coded contrl:
  119.  *    DD BB CC AA
  120.  * DD : subfunc     (_contrl[5])    5 bits
  121.  * BB : nvert. _ptsin    (_contrl[1])    11 (== # vertices, size = 2 * CC)
  122.  * CC : sizeof _intin    (_contrl[3])    8 bits
  123.  * AA : vdi opcode    (_contrl[0])    8
  124.  *
  125.  * output : void (because it is so inconsistent, individual binding funcs
  126.  *          will pull info out of the appro. binding arrays)
  127.  */
  128.  
  129. void __vdi__(unsigned long coded_contrl, int handle)
  130. {
  131.     /* decode contrl */
  132.     _contrl[0] = (unsigned short)(coded_contrl & 0xff);
  133.     _contrl[3] = (unsigned short)((coded_contrl >>= 8) & 0xff);
  134.     _contrl[1] = (unsigned short)((coded_contrl >>= 8) & 0x7ff);
  135.     _contrl[5] = (unsigned short)(coded_contrl >> 11);
  136.  
  137.     _contrl[6] = handle;
  138.  
  139.     /* call vdi */
  140.     __asm__ volatile
  141.     ("  movl    %0,    d1
  142.         movq    #0x73, d0
  143.         trap    #2"
  144.      :                /* no outputs */
  145.      : "g"(&_vdiparams[0])  /* inputs     */
  146.      : "d0", "d1", "d2", "a0", "a1", "a2"    /* clobbered regs */
  147.      );
  148. }
  149.  
  150. void vdi(void)
  151. {
  152.     __asm__ volatile
  153.     ("  movl    %0,    d1
  154.         movq    #0x73, d0
  155.         trap    #2"
  156.      :                /* no outputs */
  157.      : "g"(&_vdiparams[0])  /* inputs     */
  158.      : "d0", "d1", "d2", "a0", "a1", "a2"    /* clobbered regs */
  159.      );
  160. }
  161. /* -eof- */
  162.